Title: All Tags
---

@Html.Partial("_PostList", Model.DocumentList(Keys.PageDocuments).OrderByDescending(x => x.Get<DateTime>(BlogKeys.Published)))

<nav>
    @{
        string tag = Model.String(BlogKeys.Tag).ToLowerInvariant().Replace(' ', '-');
        tag = tag.StartsWith(".") ? tag.Substring(1) : tag;
    }
    <ul class="actions">              
            @if(Model.Bool(Keys.HasPreviousPage))
            {
                <li>
                    @{
                        string previousPage = Model.Get<int>(Keys.CurrentPage) == 2
                            ? $"/tags/{tag}.html" : $"/tags/{tag}{Model.Get<int>(Keys.CurrentPage) - 1}";
                    }
                    <a href="@previousPage"><span aria-hidden="true">&larr;</span> Newer</a>
                </li>
            }              
            @if(Model.Bool(Keys.HasNextPage))
            {
                <li>
                    @{
                        string nextPage = $"/tags/{tag}{Model.Get<int>(Keys.CurrentPage) + 1}";
                    }
                    <a href="@nextPage">Older <span aria-hidden="true">&rarr;</span></a>
                </li>
            }
    </ul>
</nav>
		
@section Sections {    
    <section class="wrapper alt style3">
        <div class="inner">
            @foreach (IDocument tagDocument in Documents[Blog.Tags]
                .GroupBy(x => x.String(BlogKeys.Tag)).Select(x => x.Where(p => p.Get<int>(Keys.CurrentPage) == 1).First())
                .OrderByDescending(x => x.Get<int>(Keys.TotalItems)))
            {
                string tagName = tagDocument.String(BlogKeys.Tag);
                string postCount = tagDocument.String(Keys.TotalItems);
                string buttonStyle = tagName == Model.String(BlogKeys.Tag) ? "special" : "";
                <a role="button" href="@Context.GetLink(tagDocument)" class="button small @buttonStyle">@tagName (@postCount)</a>
            }
        </div>
    </section>
}